<template>
    <div>
        <div class="merText">{{$t('merarcaud')}}</div>
        <div class="orderTab">
            <div class="titel">{{$t('perinf')}}</div>
            <el-row class="name">
                <el-col :span="3"><div class="grid-content bg-purple">{{$t('surname')}}</div></el-col>
                <el-col :span="5" class="right"><div class="grid-content bg-purple-light">{{firstName}}</div></el-col>
                <el-col :span="3"><div class="grid-content bg-purple">{{$t('midname')}}</div></el-col>
                <el-col :span="5" class="right"><div class="grid-content bg-purple-light">{{middleName}}</div></el-col>
                <el-col :span="3"><div class="grid-content bg-purple"></div>{{$t('nme')}}</el-col>
                <el-col :span="5" class="right"><div class="grid-content bg-purple-light">{{lastName}}</div></el-col>
            </el-row>
            <el-row class="userbvn">
                <el-col :span="3"><div class="grid-content bg-purple">BVN</div></el-col>
                <el-col :span="21" class="right"><div class="grid-content bg-purple-light">{{bvn}}</div></el-col>
            </el-row>
            <el-row class="userbth">
                <el-col :span="3"><div class="grid-content bg-purple">{{$t('birday')}}</div></el-col>
                <el-col :span="7" class="right"><div class="grid-content bg-purple-light">
                    {{mouth}}
                    <span v-if="isShow">{{$t('month')}}</span>
                </div></el-col>
                <el-col :span="7" class="right"><div class="grid-content bg-purple-light">
                    {{date}}
                    <span v-if="isShow">{{$t('day')}}</span>
                </div></el-col>
                <el-col :span="7" class="right"><div class="grid-content bg-purple-light">
                    {{year}}
                    <span v-if="isShow">{{$t('year')}}</span>
                </div></el-col>
            </el-row>
            <el-row class="handle" v-if="operate === 'review'">
                <el-col :span="3"><div class="grid-content bg-purple">{{$t('opratn')}}</div></el-col>
                <el-col :span="21" class="right">
                    <div class="grid-content bg-purple-light">
                        <el-link type="primary" :underline="isOk" @click="auditPass('SUCCESS')">{{$t('passed')}}</el-link>
                        <el-link type="primary" :underline="isOk" @click="refuse('ERROR')">{{$t('refuse')}}</el-link>
                    </div>
                </el-col>
            </el-row>
            <el-row class="handle" v-if="operate === 'examine'">
                <el-col :span="3"><div class="grid-content bg-purple">{{$t('result')}}</div></el-col>
                <el-col :span="21" class="right">
                    <div class="grid-content bg-purple-light">
                        <div class="mhsb" v-if="pass === 'SUCCESS'">
                            <img src="../pic/suc.png">
                            <span class="mjsb">{{$t('passed')}}</span>
                        </div>
                        <div class="mhsb" v-if="pass === 'ERROR'">
                            <img src="../pic/err.png">
                            <span class="mjsb">{{$t('refuse')}}</span>
                        </div>
                        <div class="mhsb" v-if="ispend === 0 && pass !== 'SUCCESS' && pass !== 'ERROR'">
                            {{$t('notappplschk')}}
                        </div>
                    </div>
                </el-col>
            </el-row>
        </div>
        <div v-if="operate === 'examine' && ispend === 1">
            <div class="csc">{{$t('submtim')}}</div>
            <div class="remark">{{auditRemarks}}</div>
        </div>
        <el-dialog :title="$t('submtim')" :visible.sync="remDialogVisible" width="30%" center :modal-append-to-body="false">
            <el-input type="textarea" autosize v-model="auditForm.auditRemark"></el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="remDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
                <el-button type="primary" @click="commitAud" v-preventReClick>{{$t('cfm')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {
    soncomaud,
    meraudit
} from '@/libs/reqlist.js'
import Cookies from 'js-cookie'
export default {
    props: ['iscan'],
    data () {
        return {
            isShow: false,
            ispend: 0,
            auditRemarks: '',
            kungfu: false,
            operate: '',
            isOk: false,
            pass: '',
            remDialogVisible: false,
            orderId: '',
            perForm: {},
            firstName: '',
            middleName: '',
            lastName: '',
            bvn: '',
            birth: '',
            auditForm: {
                orderNo: '',
                auditStatus: '',
                auditRemark: '',
                parentAuditId: null,
                appType: null
            },
            becForm: {
                productCode: null,
                rateType: 'MER_PRO_RATE_TYPE',
                rateValue: null,
                additionRateValue: null,
                takeEffectTime: null,
                loseEfficacyTime: null,
                applyTime: null,
                remark: null
            }
        }
    },
    methods: {
        getOrderFrm () {
            meraudit(JSON.stringify({ parentOrderNo: this.auditForm.orderNo })).then(res => {
                this.perForm = res.data.data[0]
                this.auditForm.auditStatus = res.data.data[0].auditStatus
                this.auditForm.orderNo = res.data.data[0].orderNo
                this.firstName = this.perForm.applyData.firstName
                this.middleName = this.perForm.applyData.middleName
                if (this.middleName === '') this.middleName = '/'
                this.lastName = this.perForm.applyData.lastName
                this.bvn = this.perForm.applyData.bvn
                this.birth = this.perForm.applyData.birth
                this.auditRemarks = this.perForm.auditRemark
                this.auditForm.appType = res.data.data[0].applyType
                if (this.perForm.auditStatus === 'SUCCESS') this.pass = 'SUCCESS'
                if (this.perForm.auditStatus === 'ERROR') this.pass = 'ERROR'
            })
        },
        auditPass (txt) {
            this.remDialogVisible = true
            this.auditForm.auditStatus = txt
        },
        refuse (txt) {
            this.remDialogVisible = true
            this.auditForm.auditStatus = txt
        },
        commitAud () {
            // if (this.$store.state.isRecheck) {
            //     let isweirm = this.$store.state.isRecheck.findIndex((value, index) => {
            //         return value.orderNo === this.auditForm.orderNo
            //     })
            //     if (isweirm === -1) {
            //         this.$store.commit('handleReview', this.auditForm)
            //     } else {
            //         this.$store.commit('handleReviewaaa', isweirm)
            //     }
            // }
            this.auditForm.auditRemark = this.auditForm.auditRemark.trim()
            soncomaud(this.auditForm).then(res => {
                if (res.data.code === '992125') {
                    this.$message.error(this.$t('audfailur'))
                }
                if (res.data.code === '000000') {
                    this.$message({
                        message: this.$t('audcomp'),
                        type: 'success'
                    })
                    if (this.auditForm.auditStatus === 'SUCCESS') {
                        this.pass = 'SUCCESS'
                        this.$parent.iscannext1('SUCCESS')
                    }
                    if (this.auditForm.auditStatus === 'ERROR') {
                        this.pass = 'ERROR'
                        this.$parent.iscannext1('ERROR')
                    }
                    this.remDialogVisible = false
                    window.localStorage.setItem('handlesp1', JSON.stringify(this.auditForm))
                    if (window.sessionStorage.getItem('size') === 'big') {
                        if (((JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus)) && ((JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus)) && ((JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus)) && ((JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus)) && ((JSON.parse(window.localStorage.getItem('handlesp5')).auditStatus))) {
                           if (((JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp2')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp5')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp5')).auditStatus === 'ERROR'))) {
                                this.$parent.handledisab()
                            }
                        }
                    }
                    if (window.sessionStorage.getItem('size') === 'small') {
                        if (((JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp3')).auditStatus === 'ERROR')) && ((JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus === 'SUCCESS') || (JSON.parse(window.localStorage.getItem('handlesp4')).auditStatus === 'ERROR'))) {
                            this.$parent.handledisabs()
                        }
                    }
                }
            })
        }
    },
    mounted () {
        if (Cookies.get('language') === 'en') this.isShow = false
        if (Cookies.get('language') === 'zh') this.isShow = true
        if (window.sessionStorage.getItem('operate')) this.operate = window.sessionStorage.getItem('operate')
        if (window.sessionStorage.getItem('orderSta') === this.$t('tobeaud')) {
            this.ispend = 0
        } else {
            this.ispend = 1
        }
        if (window.sessionStorage.getItem('handleOrder')) {
            this.auditForm.orderNo = window.sessionStorage.getItem('handleOrder')
        }
        if (this.operate === 'review') {
            this.kungfu = true
            if (window.localStorage.getItem('handlesp1')) {
                this.pass = JSON.parse(window.localStorage.getItem('handlesp1')).auditStatus
            }
            this.getOrderFrm()
        }
        if (this.operate === 'examine') {
            this.kungfu = false
            this.getOrderFrm()
        }
    },
    computed: {
        year () {
            return this.birth.substring(0, 4)
        },
        mouth () {
            let luna = this.birth.substring(5, 7)
            if (Cookies.get('language') === 'en') {
                if (luna === '01') luna = 'January'
                if (luna === '02') luna = 'February'
                if (luna === '03') luna = 'March'
                if (luna === '04') luna = 'April'
                if (luna === '05') luna = 'May'
                if (luna === '06') luna = 'June'
                if (luna === '07') luna = 'July'
                if (luna === '08') luna = 'August'
                if (luna === '09') luna = 'September'
                if (luna === '10') luna = 'October'
                if (luna === '11') luna = 'November'
                if (luna === '12') luna = 'December'
            }
            return luna
        },
        date () {
            return this.birth.substring(8, 10)
        }
    }
}
</script>

<style lang="less" scoped>
@import './pim.less';
</style>
